package com.obixlabs.security.credentialsstore.model;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class ObixPermissions extends HashMap<String, ObixPermission>
{
	private static final long serialVersionUID = -7836452406189415331L;
	
	public void add(ObixPermission permission)
	{ put(permission.getName(),permission);}

	
	/*
	 * Return a list of all the permissions in this map, but which are not in the
	 * supplied collection. 
	 * @param permissions
	 * @return
	 */
	public Collection<ObixPermission> difference(Collection<ObixPermission> permissions)
	{
		Map<String, ObixPermission> copy = 
			new HashMap<String, ObixPermission>();
		copy.putAll(this);
				
		for (ObixPermission obixPermission : permissions)
		{
			if (copy.containsKey(obixPermission.getName()))
				copy.remove(obixPermission.getName());
		} 
				
		return copy.values();
	}
}
